package de.carcophan.jimdb.service.servlets;

import javax.inject.Inject;
import javax.servlet.annotation.WebServlet;

import org.jboss.logging.Logger;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

import de.carcophan.jimdb.gwt.client.service.LoginService;
import de.carcophan.jimdb.gwt.server.Session;
import de.carcophan.jimdb.gwt.shared.dto.UserDTO;
import de.carcophan.jimdb.gwt.shared.entites.User;
import de.carcophan.jimdb.service.QueryController;

@WebServlet(name = "loginSerlvet", urlPatterns = { "/jimdb/login" })
public class LoginServiceImpl extends RemoteServiceServlet implements LoginService {

   private static Logger logger = Logger.getLogger(LoginServiceImpl.class);
   
   private static final long serialVersionUID = 1L;
   @Inject
   private QueryController queryController;
   @Inject
   private Session session;
   
   @Override
   public UserDTO login(String login, String password) {
      logger.info("LoginServiceImpl.login() " + login);
      User user = queryController.findUser(login, password);
      UserDTO userDTO = new UserDTO();
      userDTO.setLogin(user.getLogin());
      session.setUser(user);
      return userDTO;
   }

}
